package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.mystery;

import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Box;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ChainSkill extends BaseSkill {

    public ChainSkill(int level){super(level);}

    public ChainSkill(NbtCompound nbtCompound){super(nbtCompound);}

    public ChainSkill(){}

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        return "攻击时候会对附近的生物造成连锁伤害";
    }

    public SkillRarity getSkillRarity(){return SkillRarity.Mystery;}

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        /*if(!source.isOutOfWorld())
        {
            int L = 32;
            Box Box = target.getBoundingBox().stretch(L, L / 2, L).stretch(-L, -L / 2, -L);
            List<MobEntity> entityList1 = target.world.getEntitiesByClass(MobEntity.class,Box,null);
            List<MobEntity> entityList2 = null;
            Iterator iterator1 = entityList1.iterator();
            MobEntity livingEntity1 = entityList1.stream().findFirst().orElse(null);

            for(int i=0;i<3;i++)
            {
                while (iterator1.hasNext())
                {
                    if(this.Listcontain(entityList1,target) || livingEntity1 == attacker)
                    {
                        entityList1.remove(livingEntity1);
                    }
                    else
                        iterator1.next();
                }
                MobEntity target1 = target.world.getClosestEntity(entityList1,null,target,target.getX(), target.getY(),target.getZ());
                target1.damage(DamageSource.OUT_OF_WORLD,1.0f);
                entityList2.add(target1);
                target = target1;
            }
        }*/
        return true;
    }

    public boolean Listcontain(List<MobEntity> list , MobEntity mobEntity)
    {
        Iterator iterator = list.iterator();
        MobEntity mob = list.stream().findFirst().orElse(null);
        while (iterator.hasNext())
        {
            if(mob == mobEntity)
            {
                return true;
            }
        }
        return false;
    }
}


